﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint.Administration;

namespace SPaDevToolkit.Administration
{
    public abstract class SPaDatabaseManager<SA, S> : ISPaDatabaseManager<SA, S>
        where SA : SPIisWebServiceApplication   //ISPaWebServiceApplication
        where S : SPIisWebService
    {

        #region ISPaDatabaseManager<SAT,ST> Members

        public virtual DBT CreateDatabase<DBT>(SPDatabaseParameters parameters)
            where DBT : class, ISPaWebServiceApplicationDatabase
        {
            return default(DBT);
        }

        public virtual bool IsDatabaseValid(string databaseName, string databaseServer, out string errorMessage)
        {
            bool flag = true;
            errorMessage = string.Empty;
            foreach (SA application in SPaWebServiceApplication.GetApplications<SA, S>())
            {
                ISPaWebServiceApplication spAWebServiceApplication = application as ISPaWebServiceApplication;
                if (spAWebServiceApplication != null)
                {
                    if (spAWebServiceApplication.IsDatabaseNameInUse(databaseName, databaseServer))
                    {
                        flag = false;
                        errorMessage = "Database cannot be shared";
                        return flag;
                    }
                }
            }

            return flag;
        }

        #endregion
    }
}
